package com.providersave.service;

import com.providersave.mapper.StockInfoMapper;
import org.springframework.stereotype.Service;
import pojo.StockInfo;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StockInfoServiceImpl implements StockInfoService{
    @Resource
    private StockInfoMapper stockInfoMapper;

    @Override
    public boolean addStockInfo(StockInfo stockInfo) {
        boolean flag = false;
        if(stockInfoMapper.addStockInfo(stockInfo) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public boolean removeStockInfo(Long id) {
        boolean flag = false;
        if(stockInfoMapper.removeStockInfo(id) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public boolean modifyStockInfo(StockInfo stockInfo) {
        boolean flag = false;
        if(stockInfoMapper.modifyStockInfo(stockInfo) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public List<StockInfo> findStockInfoPagingByCondition(StockInfo stockInfo, Integer pageIndex, Integer pageSize) {
        //计算分页查询开始位置
        Integer _pageIndex = (pageIndex-1)*pageSize;
        return stockInfoMapper.findStockInfoPagingByCondition(stockInfo,_pageIndex,pageSize);
    }

    @Override
    public Integer findStockInfoCountByCondition(StockInfo stockInfo) {
        return stockInfoMapper.findStockInfoCountByCondition(stockInfo);
    }

    @Override
    public List<StockInfo> findUsableStockInfoPaging(Integer pageIndex, Integer pageSize) {
        //计算分页查询开始位置
        Integer _pageIndex = (pageIndex-1)*pageSize;
        return stockInfoMapper.findUsableStockInfoPaging(_pageIndex,pageSize);
    }

    @Override
    public Integer findUsableStockInfoCount() {
        return stockInfoMapper.findUsableStockInfoCount();
    }

    @Override
    public List<StockInfo> findStockInfoByGoodsId(Long goodsId) {
        return stockInfoMapper.findStockInfoByGoodsId(goodsId);
    }

    @Override
    public StockInfo findStockInfoByWarehouseAndGoods(Long warehouseId, Long goodsId) {
        return stockInfoMapper.findStockInfoByWarehouseAndGoods(warehouseId,goodsId);
    }
}
